package com.liqin.nothing.task;

import com.liqin.nothing.client.MailClient;
import com.liqin.nothing.entity.WeatherUser;
import com.liqin.nothing.service.WeatherUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @author gonghl
 * @since 2025/4/5 下午 9:22
 */

@Component
@Slf4j
@RequiredArgsConstructor
public class WeatherTask {

    private final MailClient mailClient;

    private final WeatherUserService weatherUserService;

    @Scheduled(cron = "0 0 8 * * ?")
    // @PostConstruct
    public void forecast() {
        List<WeatherUser> list = weatherUserService.list();
        for (WeatherUser weatherUser : list) {
            mailClient.sendEmail(weatherUser.getEmail(), weatherUser.getName(), weatherUser.getCity());
        }
        log.info("定时任务执行成功：" + list.size());
    }
}
